<!DOCTYPE html><html><head><meta charset="utf-8"><style></style><title>README</title></head><body><article class="markdown-body"><h1 id="dockerspring-boot"><a name="user-content-dockerspring-boot" href="#dockerspring-boot" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>基于Docker构建发布一个简单的Spring Boot应用</h1>
<h2 id="_1"><a name="user-content-_1" href="#_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>环境配置</h2>
<blockquote>
<ul>
<li>JDK1.8</li>
<li>Maven</li>
<li>IDEAJ</li>
<li>CentOS7</li>
<li>Docker1.7+</li>
</ul>
</blockquote>
<h2 id="_2"><a name="user-content-_2" href="#_2" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>搭建过程</h2>
<h3 id="1-ideajspring-boot-demo"><a name="user-content-1-ideajspring-boot-demo" href="#1-ideajspring-boot-demo" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>1. 使用IDEAJ快速生成以第一个Spring Boot Demo</h3>
<pre><code>（1）新建spring demo 工程
</code></pre>
<p><img alt="新建spring demo 工程" src="///E://hs_inAction/springboot_docker/docker-spring-boot/pics/1.jpg" /></p>
<pre><code>（2）设置springboot demo参数
</code></pre>
<p><img alt="设置springboot demo参数" src="///E://hs_inAction/springboot_docker/docker-spring-boot/pics/2.jpg" /></p>
<pre><code>（3）设置springboot项目类型
</code></pre>
<p><img alt="设置springboot项目类型" src="///E://hs_inAction/springboot_docker/docker-spring-boot/pics/3.jpg" /></p>
<pre><code>（4）设置项目名称
</code></pre>
<p><img alt="设置项目名称" src="///E://hs_inAction/springboot_docker/docker-spring-boot/pics/4.jpg" /></p>
<h3 id="2pomxml"><a name="user-content-2pomxml" href="#2pomxml" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>2.修改pom.xml</h3>
<p>修改pom.xml文件如下：<br />
<code>xml
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

    &lt;groupId&gt;com.waylau&lt;/groupId&gt;
    &lt;artifactId&gt;docker-spring-boot&lt;/artifactId&gt;
    &lt;version&gt;1.0.0&lt;/version&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;

    &lt;name&gt;docker-spring-boot&lt;/name&gt;
    &lt;description&gt;Getting started with Spring Boot and Docker&lt;/description&gt;

    &lt;parent&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
        &lt;version&gt;2.0.1.RELEASE&lt;/version&gt;
        &lt;relativePath/&gt;&lt;!-- lookup parent from repository --&gt;
    &lt;/parent&gt;

    &lt;properties&gt;
        &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
        &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
        &lt;java.version&gt;1.8&lt;/java.version&gt;
        &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
        &lt;docker.image.prefix&gt;waylau&lt;/docker.image.prefix&gt;
        &lt;spring.boot.version&gt;2.0.1.RELEASE&lt;/spring.boot.version&gt;
    &lt;/properties&gt;

    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
            &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;

    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
            &lt;/plugin&gt;

            &lt;!-- tag::plugin[] --&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;com.spotify&lt;/groupId&gt;
                &lt;artifactId&gt;docker-maven-plugin&lt;/artifactId&gt;
                &lt;version&gt;0.4.13&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;imageName&gt;${docker.image.prefix}/${project.artifactId}&lt;/imageName&gt;
                    &lt;dockerDirectory&gt;src/main/docker&lt;/dockerDirectory&gt;
                    &lt;resources&gt;
                        &lt;resource&gt;
                            &lt;targetPath&gt;/&lt;/targetPath&gt;
                            &lt;directory&gt;${project.build.directory}&lt;/directory&gt;
                            &lt;include&gt;${project.build.finalName}.jar&lt;/include&gt;
                        &lt;/resource&gt;
                    &lt;/resources&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
            &lt;!-- end::plugin[] --&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;

&lt;/project&gt;</code></p>
<p>注意：</p>
<blockquote>
<p>Maven内置变量说明： <br />
       ${basedir} 项目根目录<br />
       ${project.build.directory} 构建目录，缺省为target<br />
       ${project.build.outputDirectory} 构建过程输出目录，缺省为target/classes<br />
       ${project.build.finalName} 产出物名称，缺省为${project.artifactId}-${project.version}<br />
       ${project.packaging} 打包类型，缺省为jar<br />
       ${project.xxx} 当前pom文件的任意节点的内容</p>
</blockquote>
<h3 id="3springboothelloworld"><a name="user-content-3springboothelloworld" href="#3springboothelloworld" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>3.编写简单的Springboot主应用HelloWorld代码</h3>
<p>修改 src\main\java\com\waylau\docker_spring_boot\DockerSpringBootApplication.java</p>
<p><pre><code class="java">    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RestController;

    @SpringBootApplication
    @RestController
    public class DockerSpringBootApplication {

        @RequestMapping(value = &quot;/&quot;,method = RequestMethod.GET)
        public String home() {
            return &quot;Hello Docker World.&quot;
                    + &quot;&lt;br /&gt;Welcome to &lt;a href='http://waylau.com'&gt;waylau.com&lt;/a&gt;&lt;/li&gt;&quot;;
        }

        public static void main(String[] args) {
            SpringApplication.run(DockerSpringBootApplication.class, args);
        }
    }
</code></pre><br />
注意：</p>
<blockquote>
<p>@SpringBootApplication 表示是SpringBoot应用<br />
   @RestController 表示以Restful风格返回<br />
   @RequestMapping(value = &ldquo;/&rdquo;,method = RequestMethod.GET) 表示请求映射</p>
</blockquote>
<h3 id="4"><a name="user-content-4" href="#4" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>4.项目运行与打包</h3>
<h4 id="1"><a name="user-content-1" href="#1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>（1）编译项目</h4>
<p><img alt="编译项目" src="///E://hs_inAction/springboot_docker/docker-spring-boot/pics/5.jpg" /></p>
<h4 id="2httplocalhost8080"><a name="user-content-2httplocalhost8080" href="#2httplocalhost8080" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>（2）运行项目:运行项目后，在浏览器里输入：<a href="http://localhost:8080/">http://localhost:8080/</a> ，看到如下结果：</h4>
<p><img alt="运行项目" src="///E://hs_inAction/springboot_docker/docker-spring-boot/pics/6.jpg" /></p>
<h4 id="3"><a name="user-content-3" href="#3" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>（3）打包项目</h4>
<p><img alt="打包项目" src="///E://hs_inAction/springboot_docker/docker-spring-boot/pics/7.jpg" /></p>
<p>说明：<br />
打包项目，也可以使用其他方式：在项目根目录<br />
编译生成jar包, 保存到target文件夹内</p>
<pre><code class="shell">$ mvn package
</code></pre>

<h4 id="4jar"><a name="user-content-4jar" href="#4jar" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>（4）运行生成的jar包</h4>
<pre><code class="shell">$ java -jar target/docker-spring-boot-1.0.0.jar
</code></pre>

<pre><code class="shell">&gt;&gt;
  .   ____          _            __ _ _
 /\\ / __
_'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.1.RELEASE)

2018-05-14 00:18:45.899  INFO 4152 --- [           main] c.w.d.DockerSpringBootApplication        : Starting DockerSpringBootApplication v1.0.0 on LAPTOP-QVOLDTI6 with PID 4152 (D:\SVN\distributed\springboot_docker\docker-spring-boot\target\docker-spring-boot-1.0.0.jar started by HY in D:\SVN\distributed\springboot_docker\docker-spring-boot)
2018-05-14 00:18:45.915  INFO 4152 --- [           main] c.w.d.DockerSpringBootApplication        : No active profile set, falling back to default profiles: default
2018-05-14 00:18:46.040  INFO 4152 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7cef4e59: startup date [Mon May 14 00:18:46 CST 2018]; root of context hierarchy
2018-05-14 00:18:48.415  INFO 4152 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-05-14 00:18:48.478  INFO 4152 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-05-14 00:18:48.478  INFO 4152 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.29
2018-05-14 00:18:48.493  INFO 4152 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Python27\Scripts\bin\Bin\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Java\jdk1.8.0_121\bin;C:\Program Files\Java\jdk1.8.0_121\jre\bin\C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Python27\;E:\Git\cmd\;D:\Qt\bin\;D:\MinGW\bin\;C:\Python27\Scripts\graphviz-2.38\release\bin;C:\Python27\Scripts\;D:\MicrosoftMPI\Bin\;C:\Users\HY\pc2-9.5.2\bin\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\apache-maven-3.5.3\bin;C:\Program Files\TortoiseSVN\bin;C:\Users\HY\AppData\Local\Microsoft\WindowsApps;.]
2018-05-14 00:18:49.353  INFO 4152 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-05-14 00:18:49.353  INFO 4152 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3313 ms
2018-05-14 00:18:49.540  INFO 4152 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-05-14 00:18:49.556  INFO 4152 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-05-14 00:18:49.556  INFO 4152 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-05-14 00:18:49.556  INFO 4152 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-05-14 00:18:49.556  INFO 4152 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-05-14 00:18:49.744  INFO 4152 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-14 00:18:50.150  INFO 4152 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7cef4e59: startup date [Mon May 14 00:18:46 CST 2018]; root of context hierarchy
2018-05-14 00:18:50.291  INFO 4152 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped &quot;{[/],methods=[GET]}&quot; onto public java.lang.String com.waylau.docker_spring_boot.DockerSpringBootApplication.home()
2018-05-14 00:18:50.291  INFO 4152 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped &quot;{[/error]}&quot; onto public org.springframework.http.ResponseEntity&lt;java.util.Map&lt;java.lang.String, java.lang.Object&gt;&gt; org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-05-14 00:18:50.306  INFO 4152 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped &quot;{[/error],produces=[text/html]}&quot; onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-05-14 00:18:50.384  INFO 4152 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-14 00:18:50.384  INFO 4152 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-14 00:18:50.619  INFO 4152 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-05-14 00:18:50.759  INFO 4152 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-05-14 00:18:50.775  INFO 4152 --- [           main] c.w.d.DockerSpringBootApplication        : Started DockerSpringBootApplication in 5.5 seconds (JVM running for 6.762)
</code></pre>

<h3 id="5docker"><a name="user-content-5docker" href="#5docker" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>5.使用docker容器部署项目</h3>
<p>创建文件 <code>src/main/docker/Dockerfile</code>:</p>
<pre><code class="dockerfile">FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD docker-spring-boot-1.0.0.jar app.jar
ENTRYPOINT [&quot;java&quot;,&quot;-Djava.security.egd=file:/dev/./urandom&quot;,&quot;-jar&quot;,&quot;/app.jar&quot;]
</code></pre>

<ul>
<li><code>VOLUME</code> 指定了临时文件目录为<code>/tmp</code>。其效果是在主机 <code>/var/lib/docker</code> 目录下创建了一个临时文件，并链接到容器的<code>/tmp</code>。该步骤是可选的。<code>/tmp</code>目录用来持久化到 Docker 数据文件夹，因为 Spring Boot 使用的内嵌 Tomcat 容器默认使用<code>/tmp</code>作为工作目录</li>
<li>项目的 jar 文件作为 &ldquo;app.jar&rdquo; 添加到容器的</li>
<li><code>ENTRYPOINT</code> 执行项目 app.jar。为了缩短 <a href="http://wiki.apache.org/tomcat/HowTo/FasterStartUp#Entropy_Source">Tomcat 启动时间</a>，添加一个系统属性指向 &ldquo;/dev/urandom&rdquo; 作为 Entropy Source</li>
</ul>
<p>在安装有docker的CentOS7主机中（如果没有mvn，先安装maven），执行构建成为 docker image:</p>
<pre><code class="shell">$ mvn package docker:build
</code></pre>

<p>运行 Docker Image</p>
<pre><code class="shell">$ docker run -p 8080:8080 -t waylau/docker-spring-boot
</code></pre>

<p><pre><code class="shell">&gt;&gt;

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.1.RELEASE)

2018-05-14 00:18:45.899  INFO 4152 --- [           main] c.w.d.DockerSpringBootApplication        : Starting DockerSpringBootApplication v1.0.0 on LAPTOP-QVOLDTI6 with PID 4152 (D:\SVN\distributed\springboot_docker\docker-spring-boot\target\docker-spring-boot-1.0.0.jar started by HY in D:\SVN\distributed\springboot_docker\docker-spring-boot)
2018-05-14 00:18:45.915  INFO 4152 --- [           main] c.w.d.DockerSpringBootApplication        : No active profile set, falling back to default profiles: default
2018-05-14 00:18:46.040  INFO 4152 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7cef4e59: startup date [Mon May 14 00:18:46 CST 2018]; root of context hierarchy
2018-05-14 00:18:48.415  INFO 4152 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-05-14 00:18:48.478  INFO 4152 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-05-14 00:18:48.478  INFO 4152 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.29
2018-05-14 00:18:48.493  INFO 4152 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Python27\Scripts\bin\Bin\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Java\jdk1.8.0_121\bin;C:\Program Files\Java\jdk1.8.0_121\jre\bin\C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Python27\;E:\Git\cmd\;D:\Qt\bin\;D:\MinGW\bin\;C:\Python27\Scripts\graphviz-2.38\release\bin;C:\Python27\Scripts\;D:\MicrosoftMPI\Bin\;C:\Users\HY\pc2-9.5.2\bin\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\apache-maven-3.5.3\bin;C:\Program Files\TortoiseSVN\bin;C:\Users\HY\AppData\Local\Microsoft\WindowsApps;.]
2018-05-14 00:18:49.353  INFO 4152 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-05-14 00:18:49.353  INFO 4152 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3313 ms
2018-05-14 00:18:49.540  INFO 4152 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-05-14 00:18:49.556  INFO 4152 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-05-14 00:18:49.556  INFO 4152 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-05-14 00:18:49.556  INFO 4152 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-05-14 00:18:49.556  INFO 4152 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-05-14 00:18:49.744  INFO 4152 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-14 00:18:50.150  INFO 4152 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7cef4e59: startup date [Mon May 14 00:18:46 CST 2018]; root of context hierarchy
2018-05-14 00:18:50.291  INFO 4152 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped &quot;{[/],methods=[GET]}&quot; onto public java.lang.String com.waylau.docker_spring_boot.DockerSpringBootApplication.home()
2018-05-14 00:18:50.291  INFO 4152 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped &quot;{[/error]}&quot; onto public org.springframework.http.ResponseEntity&lt;java.util.Map&lt;java.lang.String, java.lang.Object&gt;&gt; org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-05-14 00:18:50.306  INFO 4152 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped &quot;{[/error],produces=[text/html]}&quot; onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-05-14 00:18:50.384  INFO 4152 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-14 00:18:50.384  INFO 4152 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-14 00:18:50.619  INFO 4152 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-05-14 00:18:50.759  INFO 4152 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-05-14 00:18:50.775  INFO 4152 --- [           main] c.w.d.DockerSpringBootApplication        : Started DockerSpringBootApplication in 5.5 seconds (JVM running for 6.762)
</code></pre><br />
在本地浏览器中输入 <a href="http://localhost:8080/">http://localhost:8080/</a> 可以看到运行效果</p>
<p><img alt="运行项目" src="///E://hs_inAction/springboot_docker/docker-spring-boot/pics/6.jpg" /></p>
<h2 id="_3"><a name="user-content-_3" href="#_3" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>源码下载</h2>
<h2 id="_4"><a name="user-content-_4" href="#_4" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参考</h2>
<ol>
<li><a href="https://yq.aliyun.com/articles/47344">用 Docker 构建、运行、发布一个 Spring Boot 应用. <a href="https://yq.aliyun.com/articles/47344"><a href="https://yq.aliyun.com/articles/47344">https://yq.aliyun.com/articles/47344</a></a></a></li>
</ol></article></body></html>